var {BASE} = require('../config/index')
function $http(url,method="GET",data={}){
    return new Promise((resolve,reject)=>{
        wx.request({
          url:BASE+url,
          method,
          data,
          success:(res)=>{
            resolve(res)  //给到promise的then方法
          },
          fail:(err)=>{
              reject(err) //给到promise的catch方法
          }
        })
    })
}

function $get(url,data){
    return $http(url,'GET',data)
}

function $post(url,data){
    return $http(url,'POST',data)
}


module.exports = {
    $http,
    $get,
    $post
}


